package study.Stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class MidMethod {
    public MidMethod() {
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList();
        Collections.addAll(list, new String[]{"张三", "王五", "李明", "张凯", "丽君", "张国荣"});
        list.stream().filter(new Predicate<String>() {
            public boolean test(String string) {
                return string.startsWith("张");
            }
        }).forEach((string) -> System.out.println(string));
        System.out.println("====================");
        list.stream().filter((s) -> s.startsWith("张")).forEach((s) -> System.out.println(s));
        System.out.println("2====================");
        list.stream().limit(3L).forEach((s) -> System.out.println(s));
        list.stream().skip(3L).forEach((s) -> System.out.println(s));
        System.out.println("====================");
        list.stream().skip(3L).limit(3L).forEach((s) -> System.out.println(s));
        list.stream().limit(6L).skip(3L).forEach((s) -> System.out.println(s));
        System.out.println("====================");
        Collections.addAll(list, new String[]{"张三", "张三"});
        list.stream().distinct().forEach((s) -> System.out.println(s));
        System.out.println("5====================");
        List<String> b = new ArrayList();
        Collections.addAll(b, new String[]{"李三", "王强"});
        Stream.concat(list.stream(), b.stream()).forEach((s) -> System.out.println(s));
        System.out.println("6====================");
        List<String> list2 = new ArrayList();
        Collections.addAll(list2, new String[]{"张三-1", "王五-2", "李明-3", "张凯-4", "丽君-5", "张国荣-6"});
        list2.stream().map(new Function<String, Integer>() {
            public Integer apply(String string) {
                return Integer.parseInt(string.split("-")[1]);
            }
        }).forEach((s) -> System.out.println(s));
        list2.stream().map((i) -> Integer.parseInt(i.split("-")[1])).forEach((s) -> System.out.println(s));
    }
}
